package com.zhen.config;

import org.springframework.web.servlet.HandlerInterceptor;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

public class LoginInterceptor implements HandlerInterceptor {
    @Override
    public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) throws Exception {
        System.out.println("拦截器处理："+request.getRequestURI());
        if (request.getRequestURI().equals("/login")||request.getRequestURI().equals("/loginIn")||request.getRequestURI().equals("/register")||request.getRequestURI().equals("/registerIn")){
            return true;
        }
        if(request.getSession().getAttribute("userInfo")!=null){
            return true;
        }
        System.out.println("拦截器Login拦截"+request.getRequestURI()+" userInfo==>"+request.getSession().getAttribute("userInfo"));
        request.getRequestDispatcher("/WEB-INF/jsp/login.jsp").forward(request,response);
        return false;
    }
}
